from django.db import models
from django.contrib.auth.models import User
from osmp.host.models import Product

# Create your models here.

class UserProfile(models.Model):
    '''user extra profile table'''
    user = models.ForeignKey(User, unique=True)
    mail = models.EmailField()
    mobile = models.CharField(max_length=15, blank=True)
    gtalk = models.EmailField()
    msn = models.EmailField()
    role = models.CharField(max_length=15)
    secondrole = models.CharField(max_length=100, blank=True)

    def __unicode__(self):
        return u"%s-->%s" % (self.user, self.mail)

    def __str__(self):
        return "%s-->%s" % (self.user, self.mail)

class Authority(models.Model):
    uid = models.ForeignKey(User)
    pid = models.ForeignKey(Product)
    op = models.BooleanField(choices = ((True, 'Write'), (False, 'Read')))   

    def __unicode__(self):
        if self.op:
            return u"%s--> %s : Write" % (self.uid, self.pid)
        else:
            return u"%s--> %s : Read" % (self.uid, self.pid)

    def __str__(self):
        if self.op:
            return "%s--> %s : Write" % (self.uid, self.pid)
        else:
            return "%s--> %s : Read" % (self.uid, self.pid)


